package org.hhchat.others.baidu;

import java.util.*;

/**
 * Created this one by HMH on 2017/9/27.
 */
public class exam1 {

    static public int rob(int numberOfDay,int[][] taskList ) {
        int[] hard = new int[numberOfDay];
        int[] easy = new int[numberOfDay];
        for(int i=0;i<taskList.length;i++) {
            easy[i] = taskList[i][0];
            hard[i] = taskList[i][1];
        }
        int a = 0;
        int b = 0;
        int c = 0;
        int pa = 0;
        int pb= 0;
        int pc = 0;
        for (int i = 1; i <= hard.length; i++) {
            pa = max(a, b, c);
            pb = max(a + easy[i - 1], b + easy[i - 1], c + easy[i - 1]);
            pc = a + hard[i - 1];
            a = pa;
            b = pb;
            c = pc;
        }
        return max(a, b, c);
    }

    static public int max(int a, int b, int c) {
        int max = Integer.max(a, b);
        return Integer.max(max, c);
    }

    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[][] taskList = new int[n][2];
        for(int i=0;i<n;i++) {
            taskList[i][0] = scanner.nextInt();
            taskList[i][1] = scanner.nextInt();
        }
        System.out.println(rob(n,taskList));
    }
}
